package net.lzzy.practices.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class StringUtils {
    public static String md5Encode(String origin,String salt){
        try{
            MessageDigest digest=MessageDigest.getInstance("MD5");
            if(salt !=null&&salt.length()>0){
                origin+=salt;
            }
            digest.update(origin.getBytes());
            byte[] bytes=digest.digest();
            StringBuilder builder=new StringBuilder();
            int i;
            for(byte b: bytes){
                i=b;
                if(i<0){
                    i+=256;
                }
                if(i<16){
                    builder.append("0");
                }
                builder.append(Integer.toHexString(i));
            }
            return builder.toString();
        }catch(NoSuchAlgorithmException e){
            e.printStackTrace();
            return null;
        }
    }
    public static boolean isEmpty(String str){return str==null||str.isEmpty();}
}
